package com.iflytek.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.iflytek.entity.Question;
import com.iflytek.service.QuestionService;
import com.iflytek.mapper.QuestionMapper;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @author Windows
 * @description 针对表【t_question】的数据库操作Service实现
 * @createDate 2022-09-10 18:51:38
 */
@Service
public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question>
        implements QuestionService {

    @Override
    public void saveEdit(Question question) throws Exception {
        Question q = this.getBaseMapper().selectOneByTitle(question.getTitle());
        if (q == null || (q != null && q.getId().equals(question.getId())))
            this.getBaseMapper().updateThisQuestion(question);
        else throw new Exception("标题已经被使用");
    }

    @Override
    public void saveQuestion(Question question) throws Exception {
        Question q = this.getBaseMapper().selectOneByTitle(question.getTitle());
        if (q == null) {
            question.setCreateDate(new Date());
            this.getBaseMapper().updateById(question);
        } else {
            throw new Exception("问题标题已经存在");

        }


    }

    @Override
    public void markQuestion(Integer id) {
        this.getBaseMapper().updateDel(id);
    }


}




